//
//  main.m
//  Demo0016
//
//  Created by zTercel on 13-1-15.
//  Copyright (c) 2013年 zTercel. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface ZTLNumber : NSValue

-(id) initWithChar:(char)value;
-(id) initWithShort:(short)value;
-(id) initWithInteger:(NSInteger)value;

+(ZTLNumber*) numberWithChar:(char)value;
+(ZTLNumber*) numberWithShort:(short)value;
+(ZTLNumber*) numberWithInteger:(NSInteger)value;

-(char) charValue;
-(short) shortValue;
-(NSInteger) integerValue;

@end


@implementation ZTLNumber
{
    id _value;
}

-(id) initWithChar:(char)value
{
    self = [super init];
    if (self)
    {
        _value = [NSValue valueWithBytes:&value objCType:"char"];
    }
    
    return self;
}

-(id) initWithShort:(short)value
{
    self = [super init];
    if (self)
    {
        _value = [NSValue valueWithBytes:&value objCType:"short"];
    }
    
    return self;
}

-(id) initWithInteger:(NSInteger)value
{
    self = [super init];
    if (self)
    {
        _value = [NSValue valueWithBytes:&value objCType:"NSInteger"];
    }
    
    return self;
}

+(ZTLNumber*) numberWithChar:(char)value
{
    return [[ZTLNumber alloc] initWithChar:value];
}

+(ZTLNumber*) numberWithShort:(short)value
{
    return [[ZTLNumber alloc] initWithShort:value];
}

+(ZTLNumber*) numberWithInteger:(NSInteger)value
{
    return [[ZTLNumber alloc] initWithInteger:value];
}

-(char) charValue
{
    char Value = 0;
    [_value getValue:&Value];
    return Value;
}

-(short) shortValue;
{
    short Value = 0;
    [_value getValue:&Value];
    return Value;
}

-(NSInteger) integerValue
{
    NSInteger Value = 0;
    [_value getValue:&Value];
    return Value;
}

@end

int main(int argc, const char * argv[])
{
    @autoreleasepool {
        {
            NSInteger intNumber = 1101;
            ZTLNumber* Number = [ZTLNumber numberWithInteger:intNumber];
            NSLog(@"%li", [Number integerValue]);
            
        }
        
        {
            char charNumber = 'A';
            ZTLNumber* Number = [ZTLNumber numberWithChar:charNumber];
            NSLog(@"%c", [Number charValue]);
        }
        
        {
            short shortNumber = 110;
            ZTLNumber* Number = [ZTLNumber numberWithShort:shortNumber];
            NSLog(@"%i", [Number shortValue]);
        }
    }
    return 0;
}

